package com.cskaoyan.model.admin.bo;


import com.cskaoyan.bean.MarketGoodsProduct;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.math.BigDecimal;

public class ProductsEntityOfGoodsCreateBO {
    /**
     * number : 2
     * price : 3
     * id : 0
     * specifications : ["23"]
     * url :
     */
    private String number;
    private String price;
    private int id;
    private String[] specifications;
    private String url;
    private MarketGoodsProduct marketGoodsProduct = new MarketGoodsProduct();



    public void setNumber(String number) {
        this.number = number;
        try{
            int result = Integer.parseInt(number);
            marketGoodsProduct.setNumber(result);
        }catch (NumberFormatException e){
            e.printStackTrace();
        }
    }

    public void setPrice(String price) {
        this.price = price;
        try{
            double doublePrice = Double.parseDouble(price);
            marketGoodsProduct.setPrice(new BigDecimal(doublePrice));
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public void setId(int id) {
        this.id = id;
    }

    public void setSpecifications(String[] specifications) {
        this.specifications = specifications;
        String strings = null;
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            strings = objectMapper.writeValueAsString(specifications);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        marketGoodsProduct.setSpecifications(strings);
    }

    public void setUrl(String url) {
        this.url = url;
        marketGoodsProduct.setUrl(url);
    }

    public String getNumber() {
        return number;
    }

    public String getPrice() {
        return price;
    }

    public int getId() {
        return id;
    }

    public String[] getSpecifications() {
        return specifications;
    }

    public String getUrl() {
        return url;
    }

    public MarketGoodsProduct getMarketGoodsProduct() {
        return marketGoodsProduct;
    }
}
